var g_mainScene;
// main scene
var MainScene = cc.Scene.extend({
    _mapFiles : null,
    ctor:function () {
        this._super();
        g_mainScene=this;
        this._mapFiles=new Array();

        var filename=JsonResource("maps.json");
        this.initMaps(filename);

        filename = ArmtResource("enemyEs");
        ArmatureResourceLoad( filename );
        filename = ArmtResource("heroEs");
        ArmatureResourceLoad( filename );
        filename = ArmtResource("thingEs");
        ArmatureResourceLoad( filename );

        filename = ArmtResource("xztx");
        ArmatureResourceLoad( filename );
        filename = ArmtResource("ywtx");
        ArmatureResourceLoad( filename );
    },
    onEnter:function () {
        this._super();

        var mainLayer=new MainLayer();
        this.addChild(mainLayer);

        var controlLayer=new ControlLayer();
        this.addChild(controlLayer);

        var uiLayer=new UILayer();
        this.addChild(uiLayer);

        var overLayer=new OverLayer();
        overLayer.setVisible(false);
        this.addChild(overLayer);

    },
    onEnterTransitionDidFinish : function(){
        this._super();
        var control = GetControlLayer();
        if( control ){
            control.setControlTarget( GetHero() );
        }
        var filename = AudioResource("aMain.mp3");
        cc.audioEngine.playMusic(filename,true);
    },
    onExit : function() {
        this._mapFiles.splice(0,this._mapFiles.length);
        this._super();
    },
    ///////////////////////////////////////
    initMaps : function(filename){
        var configJson=CreateJsonWithFile(filename);
        if( configJson ){
            for ( var i=0;i<configJson.files.length;i++){
                var file = configJson.files[i];
                this._mapFiles.push(file);
            }
            cc.log("map,init down,length: "+this._mapFiles.length);
        }else{
            cc.log("map,json invalid,file name: "+filename);
        }
    }
});
GetMapFile=function(level){
    if(g_mainScene){
        cc.log("getting maps by level: "+level);
        return g_mainScene._mapFiles[level];
    }else{
        cc.log("g_mainScene is invalid");
    }
}